package sub.helper
{
	import define.CharacterConst;
	
	import mx.events.FlexEvent;
	
	import sub.event.CharInfoEvent;
	import sub.view.CharInfo;
	
	public class CharInfoHelper
	{
		public function CharInfoHelper()
		{
			if(_instance != null)
				throw new Error("Singleton!");
			_instance = this;
		}
		// 实例
		private static var _instance:CharInfoHelper;
		
		public static function getInstance():CharInfoHelper
		{
			if(_instance == null)
				new CharInfoHelper();
			return _instance;
		}
		// ↑↑↑ Singleton ↑↑↑		
		private var _view:CharInfo;
		
		public function creationCompleteListener(event:FlexEvent):void
		{
			this._view = event.currentTarget as CharInfo;
			
			_view.cobClass.dataProvider = CharacterConst.getAllClasses();
		}
		
		public function cobClassChange():void
		{
			var propClass:String = this._view.cobClass.selectedLabel;
			_view.cobTalent.dataProvider = CharacterConst.getTalents(propClass);
			
			_view.btnFinish.enabled = false;
		}
		
		public function cobTalentChange():void
		{
			_view.btnFinish.enabled = true;
		}
		
		public function btnFinishClick():void
		{
			var propClass:String = this._view.cobClass.selectedLabel;
			var propTalent:String = this._view.cobTalent.selectedLabel;
			_view.dispatchEvent(new CharInfoEvent(CharInfoEvent.CHAR_INFO_EVENT_FINISH, propClass, propTalent));
		}
		
		public function btnCancelClick():void
		{
			_view.dispatchEvent(new CharInfoEvent(CharInfoEvent.CHAR_INFO_EVENT_CANCEL));
		}
		
	}
}